package com.czy.fx.day1.scene;

import com.sun.xml.internal.ws.api.ResourceLoader;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Cursor;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.stage.Stage;

import java.net.URL;

public class demo1 extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) throws Exception {
        URL resource = this.getClass().getClassLoader().getResource("logo.png");
        System.out.println(resource);
        System.out.println(resource.toExternalForm());

        Group group = new Group();
        Scene scene = new Scene(group);

        //场景光标变成 自定义图片
        scene.setCursor(Cursor.cursor(resource.toExternalForm()));

        Button button = new Button();
        button.setText("按钮");
        button.setPrefWidth(100);
        button.setPrefHeight(100);
        /*设置光标，鼠标移入变成 手*/
        button.setCursor(Cursor.HAND);
        button.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                //点击按钮，打开官网
                getHostServices().showDocument("https://xstsyg.cn");
            }
        });
        group.getChildren().add(button);

        stage.setTitle("地磅管理系统");
        stage.getIcons().add(new Image(resource.toExternalForm()));
        stage.setWidth(500);
        stage.setHeight(500);

        stage.setScene(scene);
        stage.show();



        //stage.close();//关闭窗口
    }
}